package edu.zli.lazy;

/**
 * @author ZerlindaLi create at 2021/3/19 16:45
 * @version 1.0.0
 * @description 懒汉模式内部类单例
 * 内部类使用时才会被JVM加载，初始化静态成员变量
 * 缺点：不好看
 */
public class LazyStaticInnerClassSingle {

    private LazyStaticInnerClassSingle(){
        if(LazyHolder.INSTANCE!=null) {
//            System.out.println("不允许非法访问！");
            throw new RuntimeException("不允许非法访问");
        }
    }

    public LazyStaticInnerClassSingle getInstance() {
            return LazyHolder.INSTANCE;
    }

    private static class LazyHolder {
        private static final LazyStaticInnerClassSingle INSTANCE = new LazyStaticInnerClassSingle();
    }
}
